/******************************************************************************
Project    : Real time rtsp server library base on live555
*******************************************************************************
File Name    :  <AudioRTimeServerMediaSubsession.h>:  audio real time SMSS head file
Module Name  :  
Description  :  None
History      :
 No.   Ver.     Date        Designed by  Comment
-----+--------+----------+------------+---------------------------------------
 001   0.00.01  06/08/2015  <3G@LIURENHUA>   <audio real time SMSS head file>
*******************************************************************************/
#ifndef _AUDIO_RTIME_SERVER_MEDIA_SUBSESSION_H
#define _AUDIO_RTIME_SERVER_MEDIA_SUBSESSION_H

#include <liveMedia.hh>
#ifdef LOCAL_SOCK_INPUT
#include <LocalUdpSocket.h>
#endif /* LOCAL_SOCK_INPUT */

#include "RealTimeRtspServer_common.h"

/******************************************************************************
  class declaration
 ******************************************************************************/
class 
AudioRTimeServerMediaSubsession : public OnDemandServerMediaSubsession
{
public:
	/* Create new server media session object */
	static AudioRTimeServerMediaSubsession * createNew(
							UsageEnvironment & env,
							const tEsFmt eCodecId = AUDIO_FORMAT_ADTS,
#ifdef LOCAL_SOCK_INPUT
							const char  *pcIdentity = NULL,
#endif /* LOCAL_SOCK_INPUT */
							const CH_CFG_et eChCfg = CH_CFG_2,
							const FS_IDX_et eFsIdx = FS_IDX_48,
							const PROFILE_et eProfile = PROFILE_0,
							const Boolean bWideBand = False,
							const u_int8_t ucChNum = 1,
#ifdef LOCAL_SOCK_INPUT
							const u_int32_t unSBufSize = 0, 
							const u_int32_t unRBufSize = 0
#else
							queue_t *pstQue = NULL
#endif /* LOCAL_SOCK_INPUT */
							);
	
protected:
	AudioRTimeServerMediaSubsession(
							UsageEnvironment & env, 
							const tEsFmt eCodecId,
#ifdef LOCAL_SOCK_INPUT
							const char  *pcIdentity,
#endif /* LOCAL_SOCK_INPUT */
							const CH_CFG_et eChCfg,
							const FS_IDX_et eFsIdx,
							const PROFILE_et eProfile,
							const Boolean bWideBand,
							const u_int8_t ucChNum,
#ifdef LOCAL_SOCK_INPUT
							const u_int32_t unSBufSize, 
							const u_int32_t unRBufSize
#else
							queue_t *pstQue
#endif /* LOCAL_SOCK_INPUT */ 
							);
	virtual ~AudioRTimeServerMediaSubsession(void){
	};
	
	/* "estBitrate" is the stream's estimated bitrate, in kbps */
	virtual FramedSource * createNewStreamSource(
		unsigned clientSessionId, unsigned & estBitrate); 
	virtual RTPSink * createNewRTPSink(
		Groupsock * rtpGroupsock, 
		unsigned char rtpPayloadTypeIfDynamic, 
		FramedSource * inputSource);
	
private:
#ifdef LOCAL_SOCK_INPUT
	/* Save local socket identity */
	char m_cIdentity[LSOCK_ID_LENGTH];
#else
	queue_t *m_que;
#endif /* LOCAL_SOCK_INPUT */
	/* Codec identity */
	tEsFmt m_eCodecId;
	/* Channel configuration (aac using) */
	CH_CFG_et m_eChCfg;
	/* FS index (aac using) */
	FS_IDX_et m_eFsIdx;
	/* Profile identity (aac using) */
	PROFILE_et m_eProfile;
	/* Wide band (amr using) */
	Boolean m_bWideBand;
	/* Channel number (amr using) */
	u_int8_t m_ucChNum;
#ifdef LOCAL_SOCK_INPUT
	/* Local socket send buffer size */
	u_int32_t m_unSBufSize;
	/* Local socket receive buffer size */
	u_int32_t m_unRBufSize;
#endif /* LOCAL_SOCK_INPUT */
};
#endif /* _AUDIO_RTIME_SERVER_MEDIA_SUBSESSION_H */
